﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using DtCms.Model;

namespace DtCms.Web
{
	public partial class picture : DtCms.Web.UI.BasePage
	{
		public int kindId = (int)Channel.Pictures;
		public int pcount = 0; //总条数
		public int page; //当前页
		public int pagesize; //设置每页显示的大小

		public int classId;
		public string pwhere = "IsLock=0"; //查询条件

		public string renzhengKey;	// 认证筛选条件

		protected void Page_Load(object sender, EventArgs e)
		{
			this.pagesize = SiteConfig.PicturePageNum_Client; //取得配置文件的显示条数
			renzhengKey = Request.Params["renzheng"];	// 获取认证筛选条件
			if (!int.TryParse(Request.Params["classId"] as string, out classId))
			{
				//Server.Transfer("error.aspx");
				//return;
				classId = 0;
			}
			//取得当前页
			if (!int.TryParse(Request.Params["page"] as string, out page))
			{
				page = 0;
			}
			//查询条件,查找该类别及下面的所有记录
			if (classId > 0)
			{
				pwhere += " and ClassId in(select Id from dt_Channel where KindId=" + (int)Channel.Pictures + " and ClassList like '%," + classId + ",%')";
			}
			// 查询符合认证条件的记录
			if (!string.IsNullOrEmpty(renzhengKey))
			{
				pwhere += " and Id in (select PictureId from dt_PicturesExtension where FieldId=11 and ','+Content+',' like '%," + renzhengKey + ",%')";
			}
			//System.IO.File.AppendAllText("d:\\dtcms.txt", pwhere + Environment.NewLine);
			//获得总条数
			pcount = new DtCms.BLL.Pictures().GetCount(pwhere);
			//切记绑定一下页面，Repeater属性的变量才会生效，如果你Repeater属性没有变量，下面这句可以忽略
			this.DataBind();
		}

		/// <summary>
		/// 获取当前页面的URL，并添加QueryString参数
		/// </summary>
		/// <param name="strQuery"></param>
		/// <returns></returns>
		protected string GetPictureUrl(string strQuery)
		{
			string url = URLRewrite("picture");
			url += "?" + strQuery;
			return url;
		}

		/// <summary>
		/// 获取认证列表
		/// </summary>
		/// <returns></returns>
		protected string[] GetRenzhengList()
		{
			PicturesExtension[] arr = new DtCms.BLL.Pictures().GetExtensionList("FieldId=11", null);
			System.Collections.Generic.List<string> lst = new System.Collections.Generic.List<string>();

			foreach (var it in arr)
			{
				string[] tmpArr = it.Content.Split(new string[] { ",", "，" }, StringSplitOptions.RemoveEmptyEntries);
				foreach (string k in tmpArr)
				{
					if (!lst.Contains(k)) lst.Add(k);
				}

			}

			return lst.ToArray();
		}
	}
}
